const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const httpProxyMiddleware = require("http-proxy-middleware");

var app = express();

app.use(express.static(path.resolve(__dirname, 'dist')));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
// app.use(bodyParser.json());
app.use(morgan());

app.use('/api', httpProxyMiddleware({ target: 'http://1.194.233.171:8504', changeOrigin: true }));

app.get('*', (req, res) => {
    res.sendFile(path.resolve(__dirname, 'dist/index.html'));
});

const port = process.env.port || 3333;
app.listen(port, () => {
    console.log('The server is running at http://localhost:' + port + '/');
});
